/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package vue;

import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.JPanel;
import javax.swing.SpringLayout;

/**
 *
 * @author clement
 */
public class PanelGrille extends JPanel{
    
    PanelGrille(){
        super();
    }
    
    public void paintComponent(Graphics g){
        super.paintComponent(g);
       for(int i = 0; i < this.getComponentCount(); i++){
           CaseTriangle c = (CaseTriangle) this.getComponent(i);
           
           c.setSize(new Dimension((this.getWidth()/c.getNbX())+((this.getWidth()/c.getNbX())/2) , this.getHeight()/c.getNbY()));
           c.setPreferredSize(new Dimension((this.getWidth()/c.getNbX())+((this.getWidth()/c.getNbX())/2), this.getHeight()/c.getNbY()));
          // c.repaint();
       } 
       
       SpringLayout  sp = (SpringLayout) this.getLayout();
       int largeurCase = ((CaseTriangle) this.getComponent(0)).getWidth();
        
       for(int i = 1; i < this.getComponentCount(); i++){
            
              if( i % ((CaseTriangle)this.getComponent(0)).getNbX() != 0)
              {
                sp.putConstraint(SpringLayout.WEST, this.getComponent(i), largeurCase-largeurCase/2, SpringLayout.WEST, this.getComponent(i-1));
                sp.putConstraint(SpringLayout.NORTH, this.getComponent(i), (i/((CaseTriangle)this.getComponent(0)).getNbX())*this.getComponent(i).getHeight(), SpringLayout.NORTH, this);
              }
              else
                  sp.putConstraint(SpringLayout.NORTH, this.getComponent(i), (i/((CaseTriangle)this.getComponent(0)).getNbX())*this.getComponent(i).getHeight(), SpringLayout.NORTH, this);
                 
        }
    }
    
}
